﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

namespace Taxes.Industory
{
    public partial class IndustrySecond : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request["id"];
            if (id != "")
            {
                var bll = new BLL.industry_info();
                var list = bll.GetIndustryByParentID(Convert.ToInt32(id));
                storeIndustryTop.DataSource = list;
                storeIndustryTop.DataBind();
            }
        }
        protected void btnAdd_Click(object sender, DirectEventArgs e)
        {
            if (tfTypeCode.Text.Trim() == string.Empty)
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Title = "提示",
                    Message = " 行业代码不能为空",
                    Buttons = MessageBox.Button.OK
                }).Show();
                return;
            }
            if (tfType.Text.Trim() == string.Empty)
            {
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Icon = MessageBox.Icon.INFO,
                    Title = "提示",
                    Message = "行业名称不能为空",
                    Buttons = MessageBox.Button.OK
                }).Show();
                return;
            }
            var model = new Model.industry_info();
            model.industry_no = tfTypeCode.Text.Trim();
            model.industry_name = tfType.Text.Trim();
            model.parent_id = Convert.ToInt32(Request["id"]);
            var bll = new BLL.industry_info();
            if (tbHidden.Text == "增加")
            {
                if (bll.Add(model) > 0)
                {
                    X.MessageBox.Configure(new MessageBoxConfig()
                    {
                        Icon = MessageBox.Icon.INFO,
                        Title = "提示",
                        Message = "添加行业成功!",
                         Buttons= MessageBox.Button.OK
                    }).Show();
                    tfTypeCode.Text = string.Empty;
                    tfType.Text = string.Empty;
                    window1.Hidden = true;
                    grid.Reload();
                }
                else
                {
                    X.MessageBox.Configure(new MessageBoxConfig()
                    {
                        Icon = MessageBox.Icon.INFO,
                        Title = "提示",
                        Message = "添加行业失败!",
                        Buttons = MessageBox.Button.OK
                    }).Show();
                    return;
                }
            }
            else if (tbHidden.Text == "修改")
            {
                model.ID = Convert.ToInt32(tbHiddenID.Text);
                if (bll.Update(model))
                {
                    X.MessageBox.Configure(new MessageBoxConfig()
                    {
                        Icon = MessageBox.Icon.INFO,
                        Title = "提示",
                        Message = "修改行业成功!",
                        Buttons = MessageBox.Button.OK
                    }).Show();
                    tfType.Text = string.Empty;
                    tfTypeCode.Text = string.Empty;
                    window1.Hidden = true;
                    tbHidden.Text = "增加";
                    grid.Reload();
                }
                else
                {
                    X.MessageBox.Configure(new MessageBoxConfig()
                    {
                        Icon = MessageBox.Icon.INFO,
                        Title = "提示",
                        Message = "修改行业失败!",
                        Buttons = MessageBox.Button.OK
                    }).Show();
                    return;
                }
            }
        }
        [DirectMethod]
        public string DeleteType(int id)
        {
            var bll = new BLL.industry_info();
            if (bll.Delete(id))
            {
                return "1";
            }
            return "0";
        }
    }
}